home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / toadfr12.zip / TOADFREE.ASM < prev    next >
Assembly Source File  |  1991-04-26  |  4KB  |  179 lines

  1.     title    FREE.ASM
  2.     page,132
  3.  
  4. ;Report drive free space as an ERRORLEVEL (0 if true, 1 if false).
  5. ;See usage.
  6. ;(This was requested by SEMPER BBS SYSOP who wanted to insure there
  7. ;was sufficient free space on a drive before he copied some files.)
  8. ;
  9. ;v1.2    Signs bit me!  Sigh .. should've looked up long subtraction
  10. ;    instead of winging it.  Should be ok now.
  11. ;v1.1    ok, 255000 wasn't big enough.  Now he wants BIG values
  12. ;    like 3 megabytes.
  13. ;    Well, we can do that.  Now accepts up to 0FFFFFFFFH (42Mb),
  14. ;    an unsigned long.
  15.  
  16. ;Given to the public domain
  17. ;David Kirschbaum
  18. ;Toad Hall
  19. ;
  20. CR    EQU    0DH
  21. LF    EQU    0AH
  22. DEBUG    EQU    0        ;make this 1 for Ascii display
  23.  
  24. CSEG    SEGMENT PARA 'CODE'
  25.     ASSUME CS:CSEG
  26.  
  27.  
  28.     org    100H
  29.  
  30. ToadFree    PROC    NEAR
  31.     jmp    Over
  32.  
  33. thou    dw    1000            ;constant for multiplying
  34. drive    db    0            ;current drive
  35.  
  36. usage$    db    'TOADFREE disk free space utility',CR,LF
  37.     db    'Usage:  TOADFREE D n',CR,LF
  38.     db    'Where D is a target drive',CR,LF
  39.     db    'and n is a figure from 1 to 4,294,967,295',CR,LF
  40.     db    'Returns ERRORLEVEL 0 if that much free space',CR,LF
  41.     db    '     or ERRORLEVEL 1 if less.$'
  42.  
  43.  
  44. Over:
  45.     mov    si,80H            ;PSP cmdline
  46.     cld                ;insure fwd
  47.     lodsb                ;snarf cmdline length byte
  48.     xor    ah,ah            ;clear msb
  49.     mov    cx,ax            ;into CX
  50.     jcxz    Usage            ;dummy
  51.  
  52.     mov    dx,('9' SHL 8) + '0'    ;DL='0', DH='9'
  53.     mov    ah,20H            ;handy space/constant
  54.  
  55. Space1Lup:
  56.     lodsb                ;snarf next char
  57.     cmp    al,ah    ;' '        ;space?
  58.     ja    Parm1            ;nope, hit first parm
  59.     loop    Space1Lup        ;gobble leading spaces
  60.     jmp    short Usage        ;dummy
  61.  
  62. ;First char had better be a drive parm!
  63.  
  64. Parm1:
  65.     cmp    al,'a'            ;maybe lowercase?
  66.     jb    Upper            ;nope
  67.      sub    al,ah    ;20H        ;uppercase it
  68. Upper:    cmp    al,'A'            ;We'll accept A..L
  69.     jb    Usage            ;dummy
  70.     cmp    al,'L'
  71.     ja    Usage            ;dummy
  72.     sub    al,'A'-1        ;deasciify it A = 1, B = 2
  73.     mov    drive,al        ;save for later
  74.  
  75. Parm2:    lodsb                ;snarf next char
  76.     cmp    al,dl            ;below '0'?
  77.     jb    Relup            ;yep, discard (could be whitespace)
  78.     cmp    al,dh            ;above '9'?
  79.     jbe    GotNr            ;yep, first digit of our parm
  80. Relup:    loop    Parm2            ;gobble spaces
  81.                     ;fall thru to ...
  82.  
  83. Usage:    mov    dx,offset usage$    ;'Free:...'
  84.     mov    ah,9            ;display msg
  85.     int    21H
  86.     mov    ax,4CFFH        ;ERRORLEVEL -1 for error
  87.     int    21H            ;terminate
  88.  
  89. ;Got our first legal digit
  90. GotNr:    dec    si            ;back up from that last lodsb
  91.     call    NAtoI            ;SI -> first digit
  92.                     ;returns long int in DX:AX
  93.     push    ax            ;save that request.lo
  94.     push    dx            ;and req.hi
  95.  
  96.     mov    dl,drive        ;PSP's selected drive
  97.     mov    ah,36h            ;get disk free space
  98.     int    21h            ;AX = sectors per cluster
  99.                     ;BX = available cluster count
  100.                     ;CX = bytes per sector
  101.                     ;DX = total clusters
  102.  
  103.     xor    dx,dx            ;clear for the mul
  104.     mul    bx            ;sectors per cluster * free clusters
  105.     mul    cx            ; * bytes per sector
  106.                     ;DX:AX has total free bytes
  107.  
  108.     pop    cx            ;req.hi
  109.     pop    bx            ;req.lo
  110.  
  111.     mov    si,4C00H        ;assume success, enough free
  112.     sub    ax,bx            ;free.lo - req.lo
  113.     sbb    dx,cx            ;free.hi - req.hi
  114.     adc    si,0            ;if insuff, 4C01H
  115.  
  116. IF    DEBUG
  117.     mov    ax,si            ;get the value
  118.     add    al,'0'            ;asciify
  119.     mov    dl,al            ;errorlevel
  120.     mov    ah,2            ;display output
  121.     int    21H
  122. ENDIF
  123.     mov    ax,si            ;get back the 4C0xH again
  124.     int    21H            ;terminate
  125.  
  126. ToadFree    ENDP
  127.  
  128.  
  129. ;from STDLIB.ZIP
  130. ; ATOUL-    Just like ATOL but this guy only does unsigned numbers.
  131. ; ATOUL- Converts the string pointed at by DS:SI to an unsigned long integer
  132. ;    value and returns this integer in the DX:AX registers.
  133. ;
  134. ;    Returns with the carry flag clear if no error, set if overflow.
  135. ;
  136.  
  137. NAtoI    proc    near
  138.     xor    cx,cx
  139.     xor    dx,dx
  140.  
  141. lp:    lodsb            ;snarf digit
  142.     cmp    al,','        ;comma?
  143.     jz    lp        ;yep, skip it
  144.     cmp    al,' '        ;space?
  145.     jz    lp        ;yep, skip it
  146.                 ;so much for error trapping
  147.     xor    al, '0'        ;deasciify
  148.     cmp    al, 10
  149.     ja    NotDigit    ;not a number, done
  150.     shl    cx, 1
  151.     rcl    dx, 1
  152.     jc    Error        ;overflow
  153.     mov    bx, cx
  154.     mov    DI, dx
  155.     shl    cx, 1
  156.     rcl    dx, 1
  157.     jc    Error        ;overflow
  158.     shl    cx, 1
  159.     rcl    dx, 1
  160.     jc    Error        ;overflow
  161.     add    cx, bx
  162.     adc    dx, DI
  163.     jc    Error        ;overflow
  164.     add    cl, al
  165.     adc    ch, 0
  166.     adc    dx, 0
  167.     jc    Error        ;overflow
  168.     jmp    lp        ;next digit, please
  169.  
  170. NotDigit:
  171.     mov    ax,cx        ;move long.lo into AX
  172.     clc            ;return CF clear for OK
  173. Error:    ret            ;jmp here if CF set for error
  174.  
  175. NAtoI    endp
  176.  
  177. CSEG    ENDS
  178.     END    ToadFree
  179.